/**
 * Created by sunkejun on 2015/10/15.
 */

$(document).ready(function(){
    var table = new ComDataTable("/admin/contacts/page",$('#dataTable'),"admin_contacts");
    var renders = {
        id:admin_contacts_list.editRender,
        sex:admin_contacts_list.sexRender,
    };
    table.setRenders(renders);
    table.init();
    admin_contacts_list.$table=table;
    //<span class="label label-primary">Enable</span>
})
var admin_contacts_list  = (function ($) {
    this.editRender = function( data, type, full, meta ) {
        return   '<button class="btn btn-sm btn-danger"  tooltip="删除"   onclick="admin_contacts_list.delete('+data+')">  <span class="fa fa-trash"></span></button>'
    }
    this.sexRender = function( data, type, full, meta ) {
        return data==0? "男":"女";
    }



    this.delete = function(id){
        swal({
            title: language.getNorlanguage().delete_title,
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: language.getNorlanguage().delete_sub,
            cancelButtonText: language.getNorlanguage().delete_cancle,
            closeOnConfirm: true,
            html: false
        }, function(){
            ComdataUtil.ajaxpostnormal('/admin/contacts/'+id,{},function(data){
                this.$table.rdraw();
            },"DELETE");
        });
    }


    this.submit = function(){
        $('#com_message').html("");
        var data = ComdataUtil.collectData("actionmodifyform");
        ComdataUtil.ajaxpost('/admin/contacts',data,this.finishAjaxLoadBack);
    }



    return this;
})(jQuery);

